package com.myprocessing.box.timer;

import java.util.Calendar;
import java.util.Formatter;
import java.util.GregorianCalendar;

import com.myprocessing.box.TextBox;
import com.myprocessing.timer.Timer;

public class DisplayTimerTextBox extends TextBox {

	private Timer timer;
	private CountDirection direction;
	private Calendar calendar = new GregorianCalendar();
	private String format;
	
	public enum CountDirection {
		DOWN, UP
	}
	
	public void drawBox(){
		
		long millis = 0; 
		
		switch (direction) {
		case UP:
			millis = timer.getElapsed();
			break;
		case DOWN:
			millis = timer.getRemaining();
			break;
		default:
			break;
		}
		
		long seconds = millis/1000;
		long minutes = seconds/60;
		long hours   = minutes/60;

		int displaySeconds = (int)seconds%60;
		int displayMinutes = (int)minutes%60;
		int displayhours   = (int)hours;
		
		calendar.set(0,0,0, displayhours, displayMinutes, displaySeconds);
		
		String display = String.format(format, calendar);//String.format("%t", calendar);
		
		setContents(display);
		
		super.drawBox();
	}

	public Timer getTimer() {
		return timer;
	}

	public void setTimer(Timer timer) {
		this.timer = timer;
	}

	public CountDirection getDirection() {
		return direction;
	}

	public void setDirection(CountDirection direction) {
		this.direction = direction;
	}

	public String getFormat() {
		return format;
	}

	public void setFormat(String format) {
		this.format = format;
	}
}
